﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Manager;
using Model;
using System.Data;
using System.Web.Script.Serialization;
namespace HealthSystem
{
    /// <summary>
    /// Summary description for SelfItem1
    /// </summary>
    public class SelfItem1 : IHttpHandler
    {
        JavaScriptSerializer jser = new JavaScriptSerializer();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string tjnd = context.Request["tjnd"] as string;
            string studentid = context.Request["studentid"] as string;
            ResultManager manager = new ResultManager();
            if (context.Request["action"] == "selfitem")
            {
                var selfresult = manager.GetSelfResult(tjnd, studentid);
                if (selfresult.Rows.Count > 0)
                {
                    List<SelfItem> list = new List<SelfItem>();
                    SelfItem item = null;
                    for (int i = 4; i < 24; i++)
                    {
                        if (i % 2 == 0)
                        {
                            if (!(selfresult.Rows[0][i] is DBNull))
                            {
                                bool isnull = selfresult.Rows[0][i] is DBNull;
                                if(!isnull)
                                {
                                    item = new SelfItem();

                                    item.Name = selfresult.Rows[0][i].ToString();
                                    item.Value = selfresult.Rows[0][i + 1] is DBNull ? "" : selfresult.Rows[0][i + 1].ToString();
                                    list.Add(item);
                                }
                            }
                        }
                    }
                    context.Response.Write(jser.Serialize(list));
                }
            }
            if (context.Request["action"] == "selfvaccin")
            {
                var selfresult = manager.GetSelfVaccin(tjnd, studentid);
                if (selfresult.Rows.Count > 0)
                {
                    List<SelfItem> list = new List<SelfItem>();
                    SelfItem item = null;
                    for (int i = 4; i < 14; i++)
                    {
                        if (i % 2 == 0)
                        {
                            if (!(selfresult.Rows[0][i] is DBNull))
                            {
                                bool isnull = selfresult.Rows[0][i] is DBNull;
                                if (!isnull)
                                {
                                    item = new SelfItem();

                                    item.Name = selfresult.Rows[0][i].ToString();
                                    item.Value = selfresult.Rows[0][i + 1] is DBNull ? "" : selfresult.Rows[0][i + 1].ToString();
                                    list.Add(item);
                                }
                            }
                        }
                    }
                    context.Response.Write(jser.Serialize(list));
                }
            }
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}